inspector: Move the record button up
authorMatthias Clasen <mclasen@redhat.com>
Sat, 8 Nov 2014 04:19:28 +0000 (23:19 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 8 Nov 2014 04:19:28 +0000 (23:19 -0500)
Give all the page space to the content.

gtk/inspector/statistics.c
gtk/inspector/statistics.ui
gtk/inspector/statistics.ui.h
gtk/inspector/window.ui
gtk/inspector/window.ui.h

index 69c4bc8f9228506ce39908e36acc7acd251f1041..21fe86b3a1d89211ade30f61969cddff02d42d85 100644 (file)
 #include "gtkcellrenderertext.h"
 #include "gtkcelllayout.h"
 
+enum
+{
+  PROP_0,
+  PROP_BUTTON
+};
+
 struct _GtkInspectorStatisticsPrivate
 {
   GtkWidget *stack;
@@ -137,13 +143,13 @@ update_type_counts (gpointer data)
 }
 
 static void
-toggle_record (GtkToggleToolButton    *button,
+toggle_record (GtkToggleButton        *button,
                GtkInspectorStatistics *sl)
 {
-  if (gtk_toggle_tool_button_get_active (button) == (sl->priv->update_source_id != 0))
+  if (gtk_toggle_button_get_active (button) == (sl->priv->update_source_id != 0))
     return;
 
-  if (gtk_toggle_tool_button_get_active (button))
+  if (gtk_toggle_button_get_active (button))
     {
       sl->priv->update_source_id = gdk_threads_add_timeout_seconds (1,
                                                                     update_type_counts,
@@ -235,6 +241,27 @@ type_data_free (gpointer data)
   g_free (type_data);
 }
 
+static void
+visible_child_name_changed (GObject *obj, GParamSpec *pspec, GtkInspectorStatistics *sl)
+{
+  const gchar *child;
+  gboolean visible;
+
+  child = gtk_stack_get_visible_child_name (GTK_STACK (gtk_widget_get_parent (GTK_WIDGET (sl))));
+  visible = g_strcmp0 (child, "statistics") == 0;
+
+  gtk_widget_set_visible (sl->priv->button, visible);
+}
+
+static void
+parent_set (GtkWidget *widget, GtkWidget *old_parent)
+{
+  if (old_parent)
+    g_signal_handlers_disconnect_by_func (old_parent, visible_child_name_changed, widget);
+  g_signal_connect (gtk_widget_get_parent (widget), "notify::visible-child-name",
+                    G_CALLBACK (visible_child_name_changed), widget);
+}
+
 static void
 gtk_inspector_statistics_init (GtkInspectorStatistics *sl)
 {
@@ -264,6 +291,20 @@ gtk_inspector_statistics_init (GtkInspectorStatistics *sl)
     gtk_stack_set_visible_child_name (GTK_STACK (sl->priv->stack), "excuse");
 }
 
+static void
+constructed (GObject *object)
+{
+  GtkInspectorStatistics *sl = GTK_INSPECTOR_STATISTICS (object);
+
+  g_signal_connect (sl->priv->button, "toggled",
+                    G_CALLBACK (toggle_record), sl);
+
+  if (has_instance_counts ())
+    update_type_counts (sl);
+  else
+    gtk_stack_set_visible_child_name (GTK_STACK (sl->priv->stack), "excuse");
+}
+
 static void
 finalize (GObject *object)
 {
@@ -277,14 +318,63 @@ finalize (GObject *object)
   G_OBJECT_CLASS (gtk_inspector_statistics_parent_class)->finalize (object);
 }
 
+static void
+get_property (GObject    *object,
+              guint       param_id,
+              GValue     *value,
+              GParamSpec *pspec)
+{
+  GtkInspectorStatistics *sl = GTK_INSPECTOR_STATISTICS (object);
+
+  switch (param_id)
+    {
+    case PROP_BUTTON:
+      g_value_take_object (value, sl->priv->button);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+      break;
+    }
+}
+
+static void
+set_property (GObject      *object,
+              guint         param_id,
+              const GValue *value,
+              GParamSpec   *pspec)
+{
+  GtkInspectorStatistics *sl = GTK_INSPECTOR_STATISTICS (object);
+
+  switch (param_id)
+    {
+    case PROP_BUTTON:
+      sl->priv->button = g_value_get_object (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+      break;
+    }
+}
+
 static void
 gtk_inspector_statistics_class_init (GtkInspectorStatisticsClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
+  object_class->get_property = get_property;
+  object_class->set_property = set_property;
+  object_class->constructed = constructed;
   object_class->finalize = finalize;
 
+  widget_class->parent_set = parent_set;
+
+  g_object_class_install_property (object_class, PROP_BUTTON,
+      g_param_spec_object ("button", NULL, NULL,
+                           GTK_TYPE_WIDGET, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/inspector/statistics.ui");
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorStatistics, view);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorStatistics, stack);
@@ -297,8 +387,6 @@ gtk_inspector_statistics_class_init (GtkInspectorStatisticsClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorStatistics, renderer_self2);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorStatistics, column_cumulative2);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorStatistics, renderer_cumulative2);
-  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorStatistics, button);
-  gtk_widget_class_bind_template_callback (widget_class, toggle_record);
 }
 
 // vim: set et sw=2 ts=2:
index 9e72d45c8f15fe903bc3b373fb38b50aedfc2ddc..6549fe52565af3696096db279e2b5141c25ea6b6 100644 (file)
           <object class="GtkBox">
             <property name="visible">True</property>
             <property name="orientation">vertical</property>
-            <child>
-              <object class="GtkToolbar" id="toolbar">
-                <property name="visible">True</property>
-                <property name="icon-size">small-toolbar</property>
-                <child>
-                  <object class="GtkToggleToolButton" id="button">
-                    <property name="visible">True</property>
-                    <property name="icon-name">media-record-symbolic</property>
-                    <property name="tooltip-text" translatable="yes">Collect Statistics</property>
-                    <signal name="toggled" handler="toggle_record"/>
-                  </object>
-                </child>
-              </object>
-            </child>
             <child>
               <object class="GtkScrolledWindow">
                 <property name="visible">True</property>
                 <property name="expand">True</property>
                 <property name="hscrollbar-policy">automatic</property>
                 <property name="vscrollbar-policy">always</property>
-                <property name="shadow-type">in</property>
                 <child>
                   <object class="GtkTreeView" id="view">
                     <property name="visible">True</property>
index c93734611d5c16b35f7f1875058d24d44f27ef6a..583f018efa65c7b734d679646724d9989ee8b68b 100644 (file)
@@ -1,4 +1,3 @@
-N_("Collect Statistics");
 N_("Type");
 N_("Self 1");
 N_("Cumulative 1");
@@ -6,6 +5,4 @@ N_("Self 2");
 N_("Cumulative 2");
 N_("Self");
 N_("Cumulative");
-N_("Self");
-N_("Cumulative");
 N_("Enable statistics with GOBJECT_DEBUG=instance-count");
index 6162ff67b0baeca0d9d85737c98feacc330839ff..349d21070c620bbdcd11e87561ac686edc4d13de 100644 (file)
             <property name="pack-type">start</property>
           </packing>
         </child>
+        <child>
+          <object class="GtkToggleButton" id="record_statistics_button">
+            <property name="tooltip-text" translatable="yes">Collect Statistics</property>
+            <property name="halign">center</property>
+            <property name="valign">center</property>
+            <style>
+              <class name="image-button"/>
+            </style>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="icon-name">media-record-symbolic</property>
+                <property name="icon-size">1</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="pack-type">start</property>
+          </packing>
+        </child>
         <child>
           <object class="GtkStack" id="resource_buttons">
             <child>
         <child>
           <object class="GtkInspectorStatistics">
             <property name="visible">True</property>
+            <property name="button">record_statistics_button</property>
           </object>
           <packing>
             <property name="name">statistics</property>
index e1de5c1630720051bf28bb3b2d13359091539b5d..498011ce272eec48344d9da29c78196619ec3849 100644 (file)
@@ -1,6 +1,7 @@
 N_("Select an Object");
 N_("Show Details");
 N_("Show all Objects");
+N_("Collect Statistics");
 N_("Show Details");
 N_("Show all Resources");
 N_("Miscellaneous");